﻿using Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace JavaScript
{
    /// <summary>
    /// 头信息获取
    /// </summary>
    class DebugHeads
    {
        private RequestParameteData rpd;
        public DebugHeads(RequestParameteData _rpd)
        {
            this.rpd = _rpd;
        }

        public string get(string key)
        {
           ParameterItemNodeData pn = rpd.requestHeads.Find(x=> x.Key == key);
            if(pn != null){
                return pn.Value;
            }
            return "";
        }

    }

    /// <summary>
    /// 消息体获取
    /// </summary>
    class DebugBodys
    {
        private RequestParameteData rpd;
        public DebugBodys(RequestParameteData _rpd)
        {
            this.rpd = _rpd;
        }

        public object get(string key)
        {
            ParameterItemNodeData pn = rpd.requestBody.Find(x => x.Key == key);
            if (pn != null)
            {
                /*
                 String
                 Integer
                 Boolean
                 File
                 Group
                 */
                if (pn.Type == "String")
                {
                    return pn.Value;
                }
                if (pn.Type == "Integer")
                {
                    return int.Parse(pn.Value);
                }
                if (pn.Type == "Boolean")
                {
                    return bool.Parse(pn.Value);
                }
            }
            return "";
        }

    }

    /// <summary>
    /// 文件上传
    /// </summary>
    class DebugFormData
    { 
        private RequestParameteData rpd;
        public DebugFormData(RequestParameteData _rpd)
        {
            this.rpd = _rpd;
            rpd.requestForm.Clear();
        }

        public void setFile(string key, string val, string type)
        {
            rpd.requestForm.Add(new ParameterItemNodeData()
            {
                Key = key,
                Value = val,
                Type = "File",
                Parameter = type
            });
        }

        public void setText(string key, string val)
        {
            rpd.requestForm.Add(new ParameterItemNodeData()
            {
                Key = key,
                Value = val,
                Type = "Text"
            });
        }
    }

}
